<?php


namespace App\Repositories;


use LTools\Repositories\RepositoryAbstract;

class Order extends RepositoryAbstract
{
    /**
     * Order constructor.
     * @param \App\Models\Order $model
     * @author luffyzhao@vip.126.com
     */
    public function __construct(\App\Models\Order $model)
    {
        $this->model = $model;
    }

    /**
     * @param array $attributes
     * @return bool|\Illuminate\Database\Eloquent\Model|void
     * @author luffyzhao@vip.126.com
     */
    public function create(array $attributes = [])
    {
        /**
         * @var $model \App\Models\Order
         */
        $model = parent::create($attributes);
        $model->orderProducts()->createMany($attributes['products']);

        return $model;
    }


    /**
     * @param \App\Models\Order $model
     * @param array $values
     * @return \App\Models\Order|bool|\Illuminate\Database\Eloquent\Model
     * @author luffyzhao@vip.126.com
     */
    public function updateExcel(\App\Models\Order $model, array $values)
    {
        /**
         * @var $model \App\Models\Order
         */
        $model->update($values);
        $model->orderProducts()->delete();
        $model->orderProducts()->createMany($values['products']);
        return $model;
    }

}